package oopdemo.day09demo;

public class Student {
    private String id;
    private String name;
    private int age;
    // 存储学生的数组
    static Student[] sl= new Student[3];
    static int index = 0;
    public Student(String id, String name, int age) {
        // 判断学生学号是否唯一
        for (int i = 0; i < sl.length; i++) {
            if (sl[i] != null ){

                if (sl[i].getId().equals(id)){
                    // 不唯一直接返回
                    return;
                }
            }
        }
        this.id = id;
        this.name = name;
        this.age = age;
        // 添加学生
        sl[index] = this;
        index++; 
    }
    // 展示所有学生的信息
    public void show(){
        for (int i = 0; i < sl.length; i++) {
            if (sl[i] != null){
                System.out.println("姓名是:"+sl[i].getName()+", id是："+sl[i].getId()+", 年龄是:"+sl[i].getAge());
            }
        }
    }
    public static Student[] getSl() {
        return sl;
    }
    
    public static int getIndex() {
        return index;
    }
    public static void setIndex(int index) {
        Student.index = index;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    
}
